﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using LiveCharts;
using LiveCharts.Wpf;
namespace 渐变.admin_Form
{
    public partial class admin_sales : Form
    {
        public admin_sales()
        {
            InitializeComponent();
        }

        private void admin_sales_Load(object sender, EventArgs e)
        {
            this.Dock = DockStyle.Fill;
            //经济型
            string sql1 = "select Scount from Sale where CTypeId=1";
            string t1 = DBHelper.ExecuteScalar(sql1).ToString();
            
            //舒适型
            string sql2 = "select Scount from Sale where CTypeId=2";
            string t2 = DBHelper.ExecuteScalar(sql2).ToString();

            //精英型
            string sql3 = "select Scount from Sale where CTypeId=3";
            string t3 = DBHelper.ExecuteScalar(sql3).ToString();

            //SUV
            string sql5 = "select Scount from Sale where CTypeId=5";
            string t5 = DBHelper.ExecuteScalar(sql5).ToString();

            //商务型
            string sql6 = "select Scount from Sale where CTypeId=6";
            string t6 = DBHelper.ExecuteScalar(sql6).ToString();

            //电动型
            string sql7 = "select Scount from Sale where CTypeId=7";
            string t7 = DBHelper.ExecuteScalar(sql7).ToString();

            //高端型
            string sql8 = "select Scount from Sale where CTypeId=8";
            string t8 = DBHelper.ExecuteScalar(sql8).ToString();






            Func<ChartPoint, string> labelPoint = chartPoint => string.Format("{0} ({1:P})", chartPoint.Y, chartPoint.Participation);

            // Define a collection of items to display in the chart 
            SeriesCollection piechartData = new SeriesCollection
    {
        new PieSeries
        {
            Title = "经济型", Values = new ChartValues<double> {Convert.ToInt32(t1)}, DataLabels = true, LabelPoint = labelPoint
        }, new PieSeries
        {
            Title = "舒适型", Values = new ChartValues<double> {Convert.ToInt32(t2)}, DataLabels = true, LabelPoint = labelPoint
        }, new PieSeries
        {
            Title = "精英型", Values = new ChartValues<double> {Convert.ToInt32(t3)}, DataLabels = true, LabelPoint = labelPoint
        }, new PieSeries
        {
            Title = "SUV", Values = new ChartValues<double> {Convert.ToInt32(t5)}, DataLabels = true, LabelPoint = labelPoint
        }, new PieSeries
        {
            Title = "商务型", Values = new ChartValues<double> {Convert.ToInt32(t6)}, DataLabels = true, LabelPoint = labelPoint
        }, new PieSeries
        {
            Title = "电动型", Values = new ChartValues<double> {Convert.ToInt32(t7)}, DataLabels = true, LabelPoint = labelPoint
        }, new PieSeries
        {
            Title = "高端型", Values = new ChartValues<double> {Convert.ToInt32(t8) }, DataLabels = true, LabelPoint = labelPoint
        }
    };

            // You can add a new item dinamically with the add method of the collection
            // Useful when you define the data dinamically and not statically
          /*  piechartData.Add(
                new PieSeries
                {
                    Title = "Fourth Item",
                    Values = new ChartValues<double> { 25 },
                    DataLabels = true,
                    LabelPoint = labelPoint,
                    Fill = System.Windows.Media.Brushes.Gray
                }
            );*/

            // Define the collection of Values to display in the Pie Chart
            pieChart1.Series = piechartData;

            // Set the legend location to appear in the Right side of the chart
            pieChart1.LegendLocation = LegendLocation.Right;
        }

      
    }
}
